#pragma once
#include <iostream>
#include <cstring>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <linux/can.h>
#include <linux/can/raw.h>
#include <net/if.h>
#include "Channel.h"
#include "Module.h"
class CanModule :public Module{
public:
    typedef std::shared_ptr<CanModule> ptr;
    CanModule(const std::string& interface);

    ~CanModule();

    void write_message(uint32_t canId, char *buf, size_t length);
    void write_message_frame(can_frame frame);
    // 设置CAN过滤规则
    void setFilter(uint32_t canId, uint32_t mask);

    void print_frame(can_frame& frame);
    
private:
    struct ifreq ifr;             // 网络接口信息
    struct sockaddr_can can_addr; // CAN地址
    struct can_frame frame;       // CAN数据帧
};
